﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AutoWelding.UControls
{
    [DefaultEvent("Click")]
    public partial class UMenuButton : UserControl
    {
        #region 改前备份 - 250829
        //public UMenuButton()
        //{
        //    InitializeComponent();
        //}

        ///// <summary>
        ///// 按钮图标
        ///// </summary>
        //public Image BtnImg
        //{
        //    get { return pbImg.Image; }
        //    set
        //    {
        //        pbImg.Image = value;
        //    }
        //}

        ///// <summary>
        ///// 按钮文本
        ///// </summary>
        //public string BtnText
        //{
        //    get { return lbl_text.Text; }
        //    set
        //    {
        //        lbl_text.Text = value;
        //    }
        //}

        ////protected override void OnMouseEnter(EventArgs e)
        ////{
        ////    base.OnMouseEnter(e);
        ////    this.BackColor = Color.Blue; // 
        ////}

        ////protected override void OnMouseLeave(EventArgs e)
        ////{
        ////    base.OnMouseLeave(e);
        ////    this.BackColor = Color.Aqua; // 更浅
        ////}

        //protected override void OnMouseClick(MouseEventArgs e)
        //{
        //    base.OnMouseClick(e);
        //    this.BackColor = Color.Blue; // 点击后变深
        //}

        //private void pbImg_Click(object sender, EventArgs e)
        //{
        //    this.OnClick(e);
        //}

        //private void lbl_text_Click(object sender, EventArgs e)
        //{
        //    this.OnClick(e);
        //}

        //private void pbImg_MouseEnter(object sender, EventArgs e)
        //{
        //    OnMouseEnter(e);
        //}

        //private void lbl_text_MouseEnter(object sender, EventArgs e)
        //{
        //    OnMouseEnter(e);
        //}
        #endregion
        private bool isSelected;

        public UMenuButton()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 是否选中（保持深高亮）
        /// </summary>
        public bool IsSelected
        {
            get { return isSelected; }
            set
            {
                isSelected = value;
                this.BackColor = value ? Color.Blue : Color.Aqua;
            }
        }

        /// <summary>
        /// 按钮图标
        /// </summary>
        public Image BtnImg
        {
            get { return pbImg.Image; }
            set
            {
                pbImg.Image = value;
            }
        }

        /// <summary>
        /// 按钮文本
        /// </summary>
        public string BtnText
        {
            get { return lbl_text.Text; }
            set
            {
                lbl_text.Text = value;
            }
        }

        //protected override void OnMouseEnter(EventArgs e) // 再改进，通过isSelected判断状态
        //{
        //    if (!isSelected) // 如果未选中，才悬停高亮
        //    {
        //        this.BackColor = Color.Blue;
        //    }
        //    base.OnMouseEnter(e);
        //}

        //protected override void OnMouseLeave(EventArgs e)
        //{
        //    if (!isSelected) // 如果未选中，才恢复默认
        //    {
        //        this.BackColor = Color.Aqua;
        //    }
        //    base.OnMouseLeave(e);
        //}

        protected override void OnMouseClick(MouseEventArgs e)
        {

            base.OnMouseClick(e);
            this.BackColor = Color.Blue;

        }

        private void lbl_text_Click(object sender, EventArgs e)
        {
            this.OnClick(e);
        }

        private void pbImg_Click(object sender, EventArgs e)
        {
            this.OnClick(e);
        }

        private void lbl_text_MouseEnter(object sender, EventArgs e)
        {
            OnMouseEnter(e);
        }

        private void pbImg_MouseEnter(object sender, EventArgs e)
        {
            OnMouseEnter(e);
        }
    }
}
